home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / spreotus / 123tech / 123ximac.txt < prev    next >
Text File  |  1984-11-24  |  9KB  |  210 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                                    1-2-3 Macro Tips
  10.                                     The /XI Command
  11.  
  12.           The following is a set of tips on the use of the 1-2-3 macro command /XI, and
  13.           some hints on the practical application of conditional statements.  An example
  14.           of a useful looping macro is explained that lets you use 1-2-3 as a simple word
  15.           processor.
  16.  
  17.           Designing a Cleaner Printout
  18.  
  19.           An easy way to get cleaner looking printouts from spreadsheets is to cause all
  20.           cells with a value of zero to appear blank.  To do this we can use the /XI or If
  21.           command.  First we'll write a macro that checks to see if the value of a cell is
  22.           zero, and, if it is, erases it.  Then we'll expand the macro to include a loop
  23.           so that it checks a cell, blanks it if it`s zero, moves down and does the same
  24.           thing to the next cell, and so on.  Finally, we'll make the macro stop itself.
  25.  
  26.           Introducing the If Command
  27.  
  28.           The format of the If command, /XI is:  
  29.                         /XIcondition~action if condition is true
  30.  
  31.           This command lets the macro make a decision.  If a certain condition is true,
  32.           then do a specified action.
  33.  
  34.           The condition is stated as an expression and written between the "/XI" and the
  35.           tilde (~).  Because cells in 1-2-3 can have a true or false value, the condition
  36.           is stated using the cell coordinates or, preferably, the name of a cell.
  37.           Typically, the condition looks something like the following three examples:
  38.  
  39.                  NUMBER=5
  40.                  @sum(AMOUNTS)>10000
  41.                  @today>DUEDATE#and#AMOUNTDUE>0
  42.  
  43.           The action is defined by macro instructions written after the tilde.  If the
  44.           condition is true, these instructions are executed. The macro then continues on
  45.           to the next cell down, if there is one, unless the action includes an /XG,
  46.           (goto), an /XM (menu), an /XC (subroutine call) or an /XQ (quit).  If the
  47.           condition is false, the action is not executed, and the cell below is read.
  48.           Creating the "Blank" Macro
  49.  
  50.           For our macro, the action is to make the current cell blank, so the instruction
  51.           is /RE~ (/Range Erase [Return]) The condition is "the current cell equals zero."
  52.           How do we find out the value of the current cell?  Give it a range name and
  53.           proceed as shown in this \B (for Blank) macro:
  54.  
  55.                  \B  /rncHERE~~             Create the range HERE.
  56.                      /xi(HERE=0)~/re~       If it's "0", make it blank.
  57.  
  58.           By the way, any text, i.e. alpha characters, in "HERE" will also be evaluated as
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.           equal to zero and erased by this macro.  Make sure your spreadsheet is suitable
  76.           for the \B macro.
  77.  
  78.           NOTE: (To help make macros easier to read, capitalize range names, leaving all
  79.           other letters lower case and putting the conditions in parenthesis.)
  80.  
  81.           Notice the two tildes in the first line of this macro.  When you name a range,
  82.           you press [Return] to end the name.  Then you specify the range.  Pressing
  83.           [Return] again indicates the range is simply the current cell.  The tilde after
  84.           the "/re" does the same thing.
  85.  
  86.           Adding the Loop
  87.  
  88.           Next, we want the macro to move down one cell and check again for a value of
  89.           zero.  However, if we try to do this the way we did in the last "Tips" column,
  90.           by adding {down}/xg\B~, there will be a problem: The next time we try to create
  91.           the range name "HERE", it already will exist.  1-2-3 will show us where it is by
  92.           moving the cell pointer back to its old location and we won`t go anywhere.
  93.           Therefore, we need to delete the range name.  Add this line to the macro, and it
  94.           will work:
  95.  
  96.                   /rndHERE~{down}/xg\B~       Delete "HERE", move down
  97.                                               and run \B again.
  98.  
  99.           A word of caution: You might be tempted to try another approach, adding a {bs},
  100.           (backspace) between the two tildes in /rncHERE~~. This puts the cell pointer
  101.           back where it was when the command began.  Sometimes this won't affect your
  102.           worksheet, but other times it can cause problems.
  103.  
  104.           Why? Because when you redefine a name, i.e, change the cells it refers to, all
  105.           references to that cell are redefined as well. Let's say you have a formula that
  106.           adds two entries in a row -- D5+E5 -- and that our macro "passes through" D5 on
  107.           its way down to D6, D7, etc.  When the macro is on D5, the formula reads
  108.           +HERE+E5. But when it moves on, the formula continues to read +HERE+E5, even
  109.           when HERE is D2048.
  110.  
  111.               Moral:In macros, always delete range names before you move
  112.                      them.
  113.  
  114.           Stopping the Loop
  115.  
  116.           The easiest way to stop a loop is to choose a number that you know isn't in the
  117.           column and place that number in the cell where you want the macro to stop.
  118.           Often any negative number will do; we've used "-1." And now, the completed
  119.           macro:
  120.  
  121.                   \B   /rncHERE~~
  122.                        /xi(HERE)=-1~/rndHERE~/re~/xq
  123.                        /xi(HERE=0)~/re~
  124.                        /rndHERE~{down}/xg\B~
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.           Before testing for the zero value, our \B macro first checks for the last cell.
  143.           If it finds "-1", the macro thoughtfully deletes HERE (so you can use the macro
  144.           again), erases the -1, and stops. A bit more computer jargon: the "-1" (or any
  145.           special value that a program looks for) is a "flag." In this case, it flags down
  146.           the macro to stop the loop.
  147.  
  148.           Creating a Simple Word Processor
  149.  
  150.           This little gem uses /Range Justify, a handy command that rearranges a column of
  151.           long labels so that they fit within a specified width.  See your manual or HELP
  152.           screen if you're not familiar with /Range Justify.
  153.  
  154.           In /Range Justify you tell 1-2-3 how wide the text can be by pointing out a
  155.           range.  The words stay in the first column, but they extend out to the column
  156.           you point to.  In our example, the text will be two columns wide, though you can
  157.           choose any number you like.
  158.  
  159.           By the way, don`t use this macro above tables.  If you do, you won't lose any
  160.           data or change any values, but your columns will become misaligned because the
  161.           justification affects everything, all the way down the columns in question.
  162.  
  163.           Here's the macro \E for edit:
  164.  
  165.                   \E   {edit}{?}~         Edit the cell until [Return]
  166.                        /rj{right}~        Justify over two columns
  167.                        {end}{down}        Go to the bottom of the column
  168.                        /xg\E~             And start again
  169.  
  170.           The number of {right}s following the /rj determines how many columns wide the
  171.           text will be.
  172.  
  173.           To use this macro, put the cell pointer where you want to type and press [Alt]
  174.           [E].  Type away, occasionally pressing [Return] when you want to cause
  175.           justification.  To stop, press [Ctrl-Break].
  176.  
  177.           By the way, if you press [Return] before you've typed enough to go over the end
  178.           of the second column, you'll {end} up at the bottom of the worksheet.  Just
  179.           press [Up] to get out of Edit Mode, [End][Up] to get back to the last line of
  180.           the text, and [Edit] (F2) to put you back in Edit.  You will still be in the
  181.           macro.
  182.  
  183.           While this macro alone is no match for the features of the modern word
  184.           processor, it's handy for short memos and letters.  You can use it to create a
  185.           "template" worksheet with a standard heading for your letters, another for your
  186.           memos, including a cell with @today and a date format.
  187.  
  188.           In Closing
  189.  
  190.           We designed the \B macro to demonstrate general macro techniques. You can modify
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.           it to do almost anything you want to a group of cells in the worksheet.  The \E
  208.           macro is likely to be handier, and it suggests the potential of the {end} key.
  209.           Experiment.
  210.